﻿@using Weapsy.Domain.Pages
@model Weapsy.Reporting.Pages.PageModuleAdminModel

@{ 
    Layout = "";
    var display = Model.InheritPermissions ? "none" : "block";
}

<form id="editPageModuleForm" name="editPageModuleForm" data-ajax="true" data-ajax-method="PUT" data-ajax-url="/Admin/Page/UpdateModule" data-ajax-loading="#savingModule" data-ajax-success="weapsy.controlPanel.refresh" class="form-horizontal validate-form" role="form">
    <input type="hidden" id="pageId" name="pageId" value="@Model.PageId" />
    <input type="hidden" id="moduleId" name="moduleId" value="@Model.ModuleId" />
    <input type="hidden" id="pageModuleId" name="pageModuleId" value="@Model.PageModuleId" />

    <div class="form-group">
        <div class="col-md-12">
            <label class="checkbox-inline">
                <input asp-for="InheritPermissions" type="checkbox" />
                Inherit Permissions From Page  
            </label>       
        </div>
    </div>

    <div id="pageModulePermissions" class="form-group has-feedback" style="display: @display">
        <div class="col-md-12">
            <table class="table table-bordered" style="width:auto;">
                <tr>
                    <th>Role</th>
                    @for (int i = 0; i < Enum.GetValues(typeof(PermissionType)).Length; i++)
                    {
                        <th class="text-center">@Enum.GetValues(typeof(PermissionType)).GetValue(i)</th>
                    }                    
                </tr>
                @for (int i = 0; i < Model.PageModulePermissions.Count; i++)
                {
                    <tr>
                        <td>
                            @Model.PageModulePermissions[i].RoleName&nbsp;
                            <input asp-for="PageModulePermissions[i].RoleId" type="hidden" />
                            <input asp-for="PageModulePermissions[i].Disabled" type="hidden" />
                        </td>
                        @for (int j = 0; j < Model.PageModulePermissions[i].PageModulePermissionTypes.Count; j++)
                        {
                            <td class="text-center">
                                <input asp-for="PageModulePermissions[i].PageModulePermissionTypes[j].Type" type="hidden" />
                                @if (Model.PageModulePermissions[i].Disabled)
                                {
                                    <input asp-for="PageModulePermissions[i].PageModulePermissionTypes[j].Selected" type="checkbox" disabled="disabled" />
                                }
                                else
                                {
                                    <input asp-for="PageModulePermissions[i].PageModulePermissionTypes[j].Selected" type="checkbox" />
                                }
                            </td>
                        }
                    </tr>
                }
            </table>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-12">
            <button id="save" type="submit" class="btn btn-primary" title="Save">Save</button>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-12">
            <span id="savingModule" style="display:none;">
                Saving...
            </span>
        </div>
    </div>
</form>

<script type="text/javascript">
    $(document).ready(function () {
        $('#InheritPermissions').click(function () {
            if ($(this).is(":checked")) {
                $('#pageModulePermissions').slideUp(500);
            }
            else {
                $('#pageModulePermissions').slideDown(500);
            }
        });
    });
</script>